package com.wangp.mywrite.s_juc.cas;

/**
 * @author farling-wangp
 * @version 1.0
 * @date 2020/10/11 20:09
 */
public class SimulatedCAS {
    private volatile int value;

    public synchronized int compareAndSwap(int expectedValue, int newValue) {
        int oldValue = value;
        if (oldValue == expectedValue) {
            value = newValue;
        }
        return oldValue;
    }
}
